// 赢牌-碰
class winRight extends eui.Component{
    public constructor(){
        super();
        this.once(eui.UIEvent.COMPLETE,this.onComplete,this);
        this.skinName = "src/Game/gameRoom/poker/winRightSkin.exml";
    }
    private onComplete(){
        this.touchChildren = false;
    }
    private pokerValue1:eui.Image;
    private pokerValue2:eui.Image;
    private pokerValue3:eui.Image;
    private pokerValue4:eui.Image;
    private bg1:eui.Image;
    private bg2:eui.Image;
    private bg3:eui.Image;
    private bg4:eui.Image;
    
    //设置内容 （图片名称，类型[peng/碰 gang/明杠 angang/暗杠]）
    public setContent(_skinName:string,type:string="peng", chidepaiValue?: number){
        if(type == "peng"){
            this.pokerValue1.source = _skinName;
            this.pokerValue2.source = _skinName;
            this.pokerValue3.source = _skinName;
            this.pokerValue4.visible = false;
            this.bg4.visible = false;
            this.bg1.source = "winPokerUp_2_png";
            this.bg2.source = "winPokerUp_2_png";
            this.bg3.source = "winPokerUp_2_png";            
        }
        if(type == "gang"||type == "gonggang"){
            this.pokerValue1.source = _skinName;
            this.pokerValue2.source = _skinName;
            this.pokerValue3.source = _skinName;
            this.pokerValue4.source = _skinName;
            this.pokerValue4.visible = true;
            this.bg4.visible = true;
            this.bg1.source = "winPokerUp_2_png";
            this.bg2.source = "winPokerUp_2_png";
            this.bg3.source = "winPokerUp_2_png";
            this.bg4.source = "winPokerUp_2_png";
        }
        if(type == "angang"){
            this.pokerValue1.source = "";
            this.pokerValue2.source = "";
            this.pokerValue3.source = "";
            this.pokerValue4.source = _skinName;
            this.pokerValue4.visible = true;
            this.bg4.visible = true;
            this.bg1.source = "winPoker_2_png";
            this.bg2.source = "winPoker_2_png";
            this.bg3.source = "winPoker_2_png";
            this.bg4.source = "winPokerUp_2_png";
            /*this.pokerValue1.source = _skinName;
            this.pokerValue2.source = _skinName;
            this.pokerValue3.source = _skinName;
            this.pokerValue4.visible = false;
            this.bg4.visible = true;
            this.bg1.source = "winPokerUp_3_png";
            this.bg2.source = "winPokerUp_3_png";
            this.bg3.source = "winPokerUp_3_png";
            this.bg4.source = "winPoker_1_png";*/
        }
        if (type === 'chi') {
            // const pattern = /"X"+flower+"_"+value+"_png"/
            // const pattern = /X[A-Z]_[0-9]_png/
            // const patternFlower = /(?<=X)(.+?)(?=_)/
            // const patternValue = /(?<=_)(.+?)(?=_)/
            console.log(_skinName);
            const index1 = _skinName.indexOf('_')
            // const index2 = _skinName.lastIndexOf('_')
            // const value = _skinName.slice(1, index1)
            // const flower = _skinName.slice(index1, index2)
            const flower = _skinName.slice(0, index1)
            const value = _skinName.slice(index1 + 1, index1 + 2)
            console.log(flower);
            console.log(value);
            this.pokerValue1.source = flower+"_"+(parseInt(value) - 1)+"_png";
            this.pokerValue2.source = flower+"_"+(parseInt(value))+"_png";
            this.pokerValue3.source = flower+"_"+(parseInt(value) + 1)+"_png";
            var chidepai
            if (chidepaiValue === parseInt(value) + 1) {
                chidepai = this.pokerValue3
            } else if (chidepaiValue === parseInt(value) - 1) {
                chidepai = this.pokerValue1
            } else {
                chidepai = this.pokerValue2
            }
            const mask = MyLibrary.createBitmapByName('baoting-di_png')
            mask.x = 0
            mask.y = chidepai.y - 26
            mask.width = 42
            mask.height = 30
            this.addChild(mask)
            this.pokerValue4.visible = false;
            this.bg4.visible = false;
            this.bg1.source = "winPokerUp_3_png";
            this.bg2.source = "winPokerUp_3_png";
            this.bg3.source = "winPokerUp_3_png";
        }
    }
}